(function () {
    var EVENT_CLICK = Laya.Event.CLICK;
    var io = ppt.io;

    var BtnAgainPVP = (function (_super) {
        function BtnAgainPVP(playerNum) {
            BtnAgainPVP.super(this);

            this.timer = null;
            this.curTime = 30;
            this.playerNum = playerNum;

            this.init();
        }
        Laya.class(BtnAgainPVP, "", _super);
        var _proto = BtnAgainPVP.prototype;
        _proto.destroy = function () {
            _super.prototype.destroy.call(this, true);

            this.timer = null;
            this.curTime = null;
            this.playerNum = null;
        }        

        _proto.init = function () {
            this.on(EVENT_CLICK, this, function () {
                io.emit({cmd:'pvp::wait', params : {type : this.playerNum}});
            });

            this.setup();
            this.create();

            this.loop();
            Laya.timer.loop(1000, this, this.loop);
        }
        _proto.setup = function () {
            this.skin = "res/result/btn_again.png";
            this.stateNum = 1;
            this.right = 0;
        }
        _proto.create = function () {
            var timer = new Laya.Label("(" + this.curTime + ")");
                timer.fontSize = 32;
                timer.align = "center";
                timer.font = "arial";
                timer.color = "#ffffff";
                timer.size(70, 40);
                timer.pos(200, 20);

            this.timer = timer;
            this.addChild(timer);
        }
        _proto.loop = function () {
            this.curTime --;

            if(this.curTime < 0){
                Laya.timer.clear(this, this.loop);

                ppt.director.runScene(new Scene.Home);
                return;
            }
            
            this.timer.text = "(" + this.curTime + ")";
        }

        return BtnAgainPVP;
    })(Laya.Button);

    var BtnAgainPVE = (function (_super) {
        function BtnAgainPVE(total, used) {
            BtnAgainPVE.super(this);

            this.times = null;

            this.init(total, used);
        }
        Laya.class(BtnAgainPVE, "", _super);
        var _proto = BtnAgainPVE.prototype;
        _proto.destroy = function () {
            _super.prototype.destroy.call(this, true);

            this.times = null;
        }

        _proto.init = function (total, used) {
            this.on(EVENT_CLICK, this, function () {
                io.emit({cmd:'pve::wait', params : {type : 6}});
            });

            this.setup();
            this.create(total, used);
        }
        _proto.setup = function () {
            this.skin = "res/result/btn_again.png";
            this.stateNum = 1;
            this.right = 0;
        }
        _proto.create = function (total, used) {
            var times = new Laya.Label("(" + used + "/" + total + ")");
                times.fontSize = 30;
                times.font = "arial";
                times.color = "#ffffff";
                times.size(80, 36);
                times.pos(195, 23);

            this.times = times;
            this.addChild(times);
        }

        return BtnAgainPVE;
    })(Laya.Button);

    (function (_super) {
        function OperateUI(data) {
            OperateUI.super(this);

            this.btnBack = null;
            this.btnAgain = null;
            
            this.init(data);
        }
        Laya.class(OperateUI, "Com.Result.Operate", _super);
        var _proto = OperateUI.prototype;
        _proto.destroy = function () {
            _super.prototype.destroy.call(this, true);

            this.btnBack = null;
            this.btnAgain = null;
        }

        _proto.init = function (data) {
            this.setup();
            this.create(data);
        }
        _proto.setup = function () {
            this.size(920, 90);
            this.centerX = 0;
            this.y = Laya.stage.height;
            this.alpha = 0;
        }
        _proto.create = function (data) {
            var btnAgain = null;

            var btnBack = new Laya.Button("res/result/btn_back.png", "");
                btnBack.stateNum = 1;
                btnBack.on(EVENT_CLICK, this, function () {
                    ppt.director.runScene(new Scene.Home);
                });

            switch(data.mode){
                case "pvp":
                    btnAgain = new BtnAgainPVP(data.type);
                    break;
                case "pve":
                    btnAgain = new BtnAgainPVE(data.total, data.used);
                    break;
            }

            this.btnBack = btnBack;
            this.btnAgain = btnAgain;

            this.addChildren(btnBack, btnAgain);
        }
        _proto.enter = function () {
            Laya.Tween.to(this, {y : Laya.stage.height / 2 + 245, alpha : 1}, 400);
        }
        _proto.resize = function (height) {
            Laya.Tween.clearAll(this);

            this.alpha = 1;
            this.y = Laya.stage.height / 2 + 245;
        }
    })(Laya.Box);
})();